var gulp = require("gulp");
var del = require("del");
var uglify = require("gulp-uglify");
var shell = require("gulp-shell");
var qiniu = require("gulp-qiniu");
var pkg = require("./package.json");
var qiniuCfg = require("./qiniu.config.json");
var join = require("path").join;
var cdn = require("./config/cdn.cfg");

gulp.task("clean", function (cb) {
  return del(["dist/**"], cb);
});

gulp.task("img", ["clean"], function () {
  return gulp
    .src(["img/**"], {
      base: ".",
    })
    .pipe(gulp.dest("dist"));
});

gulp.task("publish:production", function () {
  var res = {};
  res.accessKey = qiniuCfg.cfg.accessKey;
  res.secretKey = qiniuCfg.cfg.secretKey;
  res.private = false;
  res.bucket = cdn.production.BUCKET;
  return gulp.src("dist/**").pipe(
    qiniu(res, {
      dir: join(
        "/",
        cdn.production.BUCKET,
        "wx-vue-online-" + cdn.production.VERSION
      ),
    })
  );
});

gulp.task("publish:development", function () {
  var res = {};
  res.accessKey = qiniuCfg.cfg.accessKey;
  res.secretKey = qiniuCfg.cfg.secretKey;
  res.private = false;
  res.bucket = cdn.development.BUCKET;
  return gulp.src("dist/**").pipe(
    qiniu(res, {
      dir: join(
        "/",
        cdn.development.BUCKET,
        "wx-vue-test-" + cdn.development.VERSION
      ),
    })
  );
});

/**
 * http://cdn.gee4.cn/zw-wx/wx-vue-img-v2/img/aboutMe/link2-1.png
 *
 */

gulp.task("publish:img", ["clean", "img"], function () {
  var res = {};
  res.accessKey = qiniuCfg.cfg.accessKey;
  res.secretKey = qiniuCfg.cfg.secretKey;
  res.private = false;
  res.bucket = "zw-wx";
  return gulp.src("dist/**").pipe(
    qiniu(res, {
      dir: join("/", "zw-wx/", "wx-vue-img-v2"),
    })
  );
});

gulp.task("release", function () {
  return gulp.src("dist/**").pipe(gulp.dest("../static-html/fzsy-wx"));
});
